package com.annotationAndReflection;

//测试Class类的创建方式
public class TestGetClass {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println("this guy is:"+person.name);

        //方式1:通过实例化的对象获得
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());//1956725890
        //方式2:Class.forname()获得 通过包名
        Class c2 = Class.forName("com.annotationAndReflection.Student");
        System.out.println(c2.hashCode());//1956725890
        //方式3:通过类名.class获得
        Class c3 = Student.class;
        System.out.println(c3.hashCode());//1956725890
        //方式4:基本内置的包装类都有一个Type属性
        Class<Integer> c4 = Integer.TYPE;
        System.out.println(c4);//int

        //获得父类类型
        Class c5 = c1.getSuperclass();
        System.out.println(c5);//class com.annotationAndReflection.Person

    }
}


class Person{
    public String name;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person{

    public Student(){
        this.name = "学生";
    }

}
class Teacher extends Person{
    public Teacher(){
        this.name = "老师";
    }
}
    